/*
 * AgendaNotePanel.java
 *
 * Created on 15 mars 2008, 15:15
 */

package sheep.view;

import edu.uci.ics.jung.graph.Edge;
import edu.uci.ics.jung.graph.impl.DirectedSparseEdge;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import javax.swing.ListSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.TableCellRenderer;
import org.jdesktop.animation.timing.Animator;
import org.jdesktop.animation.timing.TimingTarget;
import org.jdesktop.animation.timing.interpolation.PropertySetter;
import org.jdesktop.swingx.JXPanel;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.table.TableColumnExt;
import sheep.controller.Workspace;
import sheep.model.Calendrier;

import sheep.model.Task;
import sheep.model.graph.OurVertex;
import sheep.view.Component.ActionButton;
import sheep.view.Component.CalendarCellRenderer.Adapter;
import sheep.view.Component.RoundedBox;
import sheep.view.Component.RoundedPanel;
import sheep.view.Component.SheepScrollbarUI;
import sheep.view.Component.TaskManualCreateTableModel;
import sheep.view.Component.UserCellRenderer;
import sheep.view.effects.ComponentEffect;
import sheep.view.effects.CompositeEffect;
import sheep.view.effects.EffectsManager;
import sheep.view.effects.Move;
import sheep.view.effects.Rotate;
import sheep.view.graphics2d.AnimationUtil;

/**
 *
 * @author  geek
 */
public class ProjectManualEditPanel extends JXPanel {
  
private Workspace workSpace;

private Component[] repaintComponent;

private JPanel temp, temp2, temp3;

private ScreenType currentScreen;
  private TaskManualCreateTableModel usersTableModel;
  private TaskManualCreateTableModel usersTableModel2;

private static int i=0;


  
enum TaskCreateMode  {CREATE, EDIT};

private enum ScreenType { FIRST,SECOND  }
 
Animator leftFirstAnimator,rightFirstAnimator;
  
private TaskCreateMode mode= TaskCreateMode.CREATE;

 private void configureAnimations() {
        leftFirstAnimator = new Animator(300);
        leftFirstAnimator.setAcceleration(0.3f);
        leftFirstAnimator.setDeceleration(0.2f);
        leftFirstAnimator.addTarget(new PropertySetter(
                temp2, "location", new Point(-280,0)));
        leftFirstAnimator.addTarget(new PropertySetter(
                temp, "location", new Point(20,55)));    
        leftFirstAnimator.addTarget(new PropertySetter(
                temp3, "location", new Point(532,45)));
  

        rightFirstAnimator = new Animator(300);
        rightFirstAnimator.setAcceleration(0.3f);
        rightFirstAnimator.setDeceleration(0.2f);      
        rightFirstAnimator.addTarget(new PropertySetter(
                temp2, "location", new Point(15,55)));
        rightFirstAnimator.addTarget(new PropertySetter(
                temp, "location", new Point(295,55)));
        rightFirstAnimator.addTarget(new PropertySetter(
                temp3, "location", new Point(830,0)));

        

    } 
 
  
  TaskCreateMode getMode() {
    return mode;
  }

  public void setMode(TaskCreateMode mode) {
    this.mode = mode;
  }
  
  
  public Component[] getRepaintComponent() {
    return repaintComponent;
  }

  public void setRepaintComponent(Component[] repaintComponent) {
    this.repaintComponent = repaintComponent;
  }
  
  /** Creates new form AgendaNotePanel */
  public ProjectManualEditPanel(Workspace workSpace) {
    initComponents();
    this.workSpace = workSpace;

    ComponentEffect moveEffect = new Move(null, null);
    ComponentEffect rotateEffect = new Rotate(null, null, 360, 15, 10);
    CompositeEffect compositeEffect = new CompositeEffect(moveEffect);
    compositeEffect.addEffect(rotateEffect);    
    EffectsManager.setEffect(this, compositeEffect, 
		EffectsManager.TransitionType.CHANGING);
        
    configureAnimations();
    currentScreen = ScreenType.FIRST;
  }
  
  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">
  private void initComponents() {

    rightPanel = new javax.swing.JPanel();
    jPanel2 = new javax.swing.JPanel();
    addButton = new ActionButton("+ >>", new Dimension(40, 20));
    remButton = new ActionButton("<< -", new Dimension(40, 20));
    jPanel3 = new javax.swing.JPanel();
    jScrollPane2 = new javax.swing.JScrollPane();
    predecesseurTable = new JXTable();
    titleLabel1 = new javax.swing.JLabel();
    jPanel4 = new javax.swing.JPanel();
    titleLabel2 = new javax.swing.JLabel();
    jScrollPane3 = new javax.swing.JScrollPane();
    tasksTable = new JXTable();
    commentPanel = new javax.swing.JPanel();
    commentLabel = new javax.swing.JLabel();
    commentScrollPane = new javax.swing.JScrollPane();
    commentTextArea = new javax.swing.JTextArea();
    jPanel1 = new javax.swing.JPanel();
    titleLabel3 = new javax.swing.JLabel();
    jButton9 = new javax.swing.JButton();
    jPanel5 = new javax.swing.JPanel();
    jButton5 = new ActionButton();
    jButton6 = new ActionButton();
    jButton7 = new ActionButton();
    jButton8 = new ActionButton();
    leftPanel = new javax.swing.JPanel();
    titlePanel = new javax.swing.JPanel();
    titleLabel = new javax.swing.JLabel();
    titleTextField = new javax.swing.JTextField();
    calendrierPanel = new javax.swing.JPanel();
    calendrierLabel = new javax.swing.JLabel();
    endDatePanel1 = new javax.swing.JPanel();
    DurationSpinner = new javax.swing.JSpinner();
    endDateMinLabel1 = new javax.swing.JLabel();
    beginPanel = new javax.swing.JPanel();
    beginLabel = new javax.swing.JLabel();
    beginDatePicker = new org.jdesktop.swingx.JXDatePicker();
    endPanel = new javax.swing.JPanel();
    endDatePanel = new javax.swing.JPanel();
    endDatePicker = new org.jdesktop.swingx.JXDatePicker();
    endLabel = new javax.swing.JLabel();

    setLayout(null);
    setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 10));
    setOpaque(false);

    rightPanel.setOpaque(false);
    rightPanel.setLayout(new java.awt.BorderLayout());

    jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 5, 1, 5));
    jPanel2.setOpaque(false);

    addButton.setText("+ >>");
    addButton.setPreferredSize(new java.awt.Dimension(10, 23));
    addButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
           if (tasksTable.getSelectedRow()>=0){
      Task t = usersTableModel.getList().remove(tasksTable.getSelectedRow());
      usersTableModel2.getList().add(t);
      //tasksTable.setModel(usersTableModel);
      tasksTable.repaint();      
      
      //usersTableModel2.setData(list3);
      //predecesseurTable.setModel(usersTableModel2);
      predecesseurTable.repaint();
      if (getMode() == TaskCreateMode.EDIT ){
        workSpace.getCurrentTask().getGraph().addEdge(t, workSpace.getSelectedTask());
      }
            }     
      }
    });

    remButton.setText("<< -");
    remButton.setActionCommand("<<  -");
    remButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
           if (predecesseurTable.getSelectedRow()>=0){
      Task t = usersTableModel2.getList().remove(predecesseurTable.getSelectedRow());
      usersTableModel.getList().add(t);
      //tasksTable.setModel(usersTableModel);
      tasksTable.repaint();      
      
      //usersTableModel2.setData(list3);
      //predecesseurTable.setModel(usersTableModel2);
      predecesseurTable.repaint();
      
      DirectedSparseEdge edge = (DirectedSparseEdge) workSpace.getCurrentTask().getGraph().getVertex(t).findEdge(
              workSpace.getCurrentTask().getGraph().getVertex(workSpace.getSelectedTask())
              );
      if(edge != null){
        workSpace.getCurrentTask().getGraph().removeEdge(edge);
      }
//      for (Object o :workSpace.getCurrentTask().getGraph().getEdges()){
//        if ( ((OurVertex)((Edge)o).getEndpoints().getFirst()).getTask().getID() == t.getID() &&
//             ((OurVertex)((Edge)o).getEndpoints().getSecond()).getTask().getID() == workSpace.getSelectedTask().getID())
//          workSpace.getCurrentTask().getGraph().removeEdge((DirectedSparseEdge)o);
//      }
//              
//              
              
            }
      }
    });

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addComponent(remButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap())
    );
    jPanel2Layout.setVerticalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addGap(32, 32, 32)
        .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(18, 18, 18)
        .addComponent(remButton)
        .addContainerGap(32, Short.MAX_VALUE))
    );

    rightPanel.add(jPanel2, java.awt.BorderLayout.CENTER);

    jPanel3.setOpaque(false);
    jPanel3.setPreferredSize(new java.awt.Dimension(210, 400));
    jPanel3.setLayout(new java.awt.BorderLayout());

    jScrollPane2.setBorder(null);
    jScrollPane2.setPreferredSize(new java.awt.Dimension(210, 424));

    
    TableCellRenderer render = new UserCellRenderer();
    Object headers[] = {"Nom", "Date de début", "Date de fin"};  
    predecesseurTable = new JXTable();
    predecesseurTable.setShowVerticalLines(false);
    predecesseurTable.setGridColor(Color.LIGHT_GRAY);
    usersTableModel2 = new TaskManualCreateTableModel (headers, new LinkedList<Task> () );
    
    predecesseurTable.setModel(usersTableModel2);
    TaskManualCreateTableModel.setTableHeaders(predecesseurTable, usersTableModel2.getHeaders());

    predecesseurTable.setDefaultRenderer(Object.class, render);
    predecesseurTable.setColumnControlVisible(true);
    predecesseurTable.setRowHeight(40);
    predecesseurTable.setFocusable(false);
    predecesseurTable.packAll();
    predecesseurTable.setColumnSelectionAllowed(false);
    predecesseurTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    predecesseurTable.setEditable(false);
    predecesseurTable.setPreferredScrollableViewportSize(new Dimension(150, 200));     
    predecesseurTable.setPreferredSize(new Dimension(150, 200)); 
   
    predecesseurTable.getColumnExt("Date de début").setVisible(false);
    predecesseurTable.getColumnExt("Date de fin").setVisible(false);  
  jScrollPane2.getVerticalScrollBar().setUI(new SheepScrollbarUI());
        
        
        
    /*predecesseurTable.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null}
      },
      new String [] {
        "Title 1", "Title 2", "Title 3", "Title 4"
      }
    ));
     * */
    jScrollPane2.setViewportView(predecesseurTable);

    jPanel3.add(jScrollPane2, java.awt.BorderLayout.CENTER);

    titleLabel1.setFont(new java.awt.Font("Times New Roman", 1, 14));
    titleLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    titleLabel1.setText("Predecesseur");
    titleLabel1.setForeground(new java.awt.Color(255, 255, 255));
    titleLabel1.setPreferredSize(new java.awt.Dimension(81, 23));
    jPanel3.add(titleLabel1, java.awt.BorderLayout.NORTH);

    rightPanel.add(jPanel3, java.awt.BorderLayout.EAST);

    jPanel4.setOpaque(false);
    jPanel4.setPreferredSize(new java.awt.Dimension(210, 400));
    jPanel4.setLayout(new java.awt.BorderLayout());

    titleLabel2.setFont(new java.awt.Font("Times New Roman", 1, 14));
    titleLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    titleLabel2.setText("Taches connectables");
    titleLabel2.setForeground(new java.awt.Color(255, 255, 255));
    titleLabel2.setPreferredSize(new java.awt.Dimension(124, 23));
    jPanel4.add(titleLabel2, java.awt.BorderLayout.NORTH);

    jScrollPane3.setBorder(null);
    jScrollPane3.setOpaque(false);
    jScrollPane3.setPreferredSize(new java.awt.Dimension(210, 424));
 
    tasksTable = new JXTable();
    tasksTable.setShowVerticalLines(false);
    tasksTable.setGridColor(Color.LIGHT_GRAY);
    usersTableModel = new TaskManualCreateTableModel (headers, new LinkedList<Task> ());
    
    tasksTable.setModel(usersTableModel);
    TaskManualCreateTableModel.setTableHeaders(tasksTable, usersTableModel.getHeaders());

    tasksTable.setDefaultRenderer(Object.class, render);
    tasksTable.setColumnControlVisible(true);
    tasksTable.setRowHeight(40);
    tasksTable.setFocusable(false);
    tasksTable.packAll();
    tasksTable.setColumnSelectionAllowed(false);
    tasksTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tasksTable.setEditable(false);

    tasksTable.setPreferredScrollableViewportSize(new Dimension(150, 200));     
    tasksTable.setPreferredSize(new Dimension(150, 200)); 
 

    tasksTable.getColumnExt("Date de début").setVisible(false);
    tasksTable.getColumnExt("Date de fin").setVisible(false);       
  
    jScrollPane3.getVerticalScrollBar().setUI(new SheepScrollbarUI());    
    
    /*
    tasksTable.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null}
      },
      new String [] {
        "Title 1", "Title 2", "Title 3", "Title 4"
      }
    ));
    */
    jScrollPane3.setViewportView(tasksTable);

    jPanel4.add(jScrollPane3, java.awt.BorderLayout.CENTER);

    rightPanel.add(jPanel4, java.awt.BorderLayout.WEST);

    commentPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 10, 1));
    commentPanel.setOpaque(false);
    commentPanel.setLayout(new java.awt.BorderLayout(0, 10));
    commentPanel.setPreferredSize(new java.awt.Dimension(250, 200));

    commentLabel.setFont(new java.awt.Font("Times New Roman", 1, 14));
    commentLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    commentLabel.setText("Commentaires :");
    commentLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
    commentLabel.setForeground(new java.awt.Color(255, 255, 255));
    commentPanel.add(commentLabel, java.awt.BorderLayout.PAGE_START);

    commentScrollPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    commentTextArea.setPreferredSize(new java.awt.Dimension(180, 150));
    commentScrollPane.setOpaque(false);
    //commentScrollPane.setPreferredSize(new java.awt.Dimension(120, 120));

    commentTextArea.setColumns(20);
    commentTextArea.setRows(5);
    commentTextArea.setOpaque(false);
    commentTextArea.setPreferredSize(new java.awt.Dimension(250, 100));
    commentScrollPane.setViewportView(commentTextArea);

    commentPanel.add(commentScrollPane, java.awt.BorderLayout.CENTER);

    jPanel1.setOpaque(false);

    titleLabel3.setFont(new java.awt.Font("Tahoma", 1, 20));
    titleLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    titleLabel3.setText("Titre");
    titleLabel3.setForeground(new java.awt.Color(255, 255, 255));

    jButton9.setText("Retour");
    jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/button-close.png"))); // NOI18N
    jButton9.setToolTipText("Close editor");
    jButton9.setBorder(null);
    jButton9.setBorderPainted(false);
    jButton9.setContentAreaFilled(false);
    jButton9.setFocusPainted(false);
    jButton9.setFocusable(false);
    jButton9.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jButton9.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/button-close-pressed.png"))); // NOI18N
    jButton9.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/button-close-over.png"))); // NOI18N
    jButton9.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cornerQuitBttnActionPerformed(evt);
      }
    });
    
    //jButton9.setPreferredSize(new java.awt.Dimension(30, 23));

    
  
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
        .addGap(188, 188, 188)
        .addComponent(titleLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 396, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(181, 181, 181)
        .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(253, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
        .addComponent(titleLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
        .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
    );

    jPanel5.setOpaque(false);

    jButton5.setText("<<Retour");
    jButton5.setPreferredSize(new java.awt.Dimension(110, 23));
    jButton5.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (currentScreen == ScreenType.SECOND){
              rightFirstAnimator.start();
              jButton6.setVisible(true);
              //jButton5.setVisible(false);
              currentScreen = ScreenType.FIRST;
            }           
          }
        });
    
    jButton6.setText("Comentaires>>");
    jButton6.setActionCommand("Comentaires >>");
   jButton6.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (currentScreen == ScreenType.FIRST){
              leftFirstAnimator.start();
              jButton5.setVisible(true);
              //jButton6.setVisible(false);
              currentScreen = ScreenType.SECOND;
            }           
          }
        });
        
    jButton6.setPreferredSize(new java.awt.Dimension(110, 23));

    jButton7.setText("Quitter");
    jButton7.setPreferredSize(new java.awt.Dimension(100, 23));

    jButton8.setText("OK");
    jButton8.setPreferredSize(new java.awt.Dimension(100, 23));

    jButton8.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        OKBttnActionPerformed(evt);
      }
    });
    
    jButton7.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        quitBttnActionPerformed(evt);
      }
    });
    
    
    javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
    jPanel5.setLayout(jPanel5Layout);
    jPanel5Layout.setHorizontalGroup(
      jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel5Layout.createSequentialGroup()
        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(155, 155, 155)
        .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(18, 18, 18)
        .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(190, 190, 190)
        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(253, 253, 253))
    );
    jPanel5Layout.setVerticalGroup(
      jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel5Layout.createSequentialGroup()
        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    leftPanel.setOpaque(false);
    leftPanel.setPreferredSize(new java.awt.Dimension(250, 200));
    leftPanel.setLayout(new javax.swing.BoxLayout(leftPanel, javax.swing.BoxLayout.PAGE_AXIS));

    titlePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    titlePanel.setOpaque(false);
    titlePanel.setPreferredSize(new java.awt.Dimension(150, 10));
    titlePanel.setLayout(new java.awt.BorderLayout());

    titleLabel.setFont(new java.awt.Font("Times New Roman", 1, 14));
    titleLabel.setText("Nom");
    titleLabel.setForeground(new java.awt.Color(255, 255, 255));
    titlePanel.add(titleLabel, java.awt.BorderLayout.WEST);

    titleTextField.setFont(new java.awt.Font("Times New Roman", 1, 14));
    titleTextField.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    titleTextField.setText("jTextField1");
    titleTextField.setBorder(BorderFactory.createEmptyBorder());
    titleTextField.setOpaque(false);
    titleTextField.setPreferredSize(new java.awt.Dimension(120, 15));
    titleTextField.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
     
      }
    });
    titlePanel.add(titleTextField, java.awt.BorderLayout.EAST);

    leftPanel.add(titlePanel);

    calendrierPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    calendrierPanel.setOpaque(false);
    calendrierPanel.setPreferredSize(new java.awt.Dimension(160, 10));
    calendrierPanel.setLayout(new java.awt.BorderLayout());

    calendrierLabel.setFont(new java.awt.Font("Times New Roman", 1, 14));
    calendrierLabel.setText("Duree");
    calendrierLabel.setForeground(new java.awt.Color(255, 255, 255));
    calendrierPanel.add(calendrierLabel, java.awt.BorderLayout.WEST);

    endDatePanel1.setOpaque(false);
    endDatePanel1.setPreferredSize(new java.awt.Dimension(120, 25));
    endDatePanel1.setLayout(new java.awt.BorderLayout(20, 0));

    DurationSpinner.setFont(new java.awt.Font("Times New Roman", 1, 14));
    DurationSpinner.setOpaque(false);
    DurationSpinner.setBorder(BorderFactory.createEmptyBorder());
    DurationSpinner.setPreferredSize(new java.awt.Dimension(80, 15));
    DurationSpinner.addChangeListener(new ChangeListener() {

      @Override
      public void stateChanged(ChangeEvent e) {
        Date d = beginDatePicker.getDate();
        endDatePicker.setDateInMillis(d.getTime() 
                + ((Integer)DurationSpinner.getValue()-1) * 1000*3600*24);
        if((Integer)DurationSpinner.getValue() < 1)
          DurationSpinner.setValue(1);
      }
    });
    
    endDatePanel1.add(DurationSpinner, java.awt.BorderLayout.CENTER);

    endDateMinLabel1.setFont(new java.awt.Font("Times New Roman", 1, 14));
    endDateMinLabel1.setText("jours");
    endDateMinLabel1.setForeground(new java.awt.Color(255, 255, 255));
    endDatePanel1.add(endDateMinLabel1, java.awt.BorderLayout.EAST);

    calendrierPanel.add(endDatePanel1, java.awt.BorderLayout.EAST);

    leftPanel.add(calendrierPanel);

    beginPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    beginPanel.setOpaque(false);
    beginPanel.setPreferredSize(new java.awt.Dimension(160, 10));
    beginPanel.setLayout(new java.awt.BorderLayout());

    beginLabel.setFont(new java.awt.Font("Times New Roman", 1, 14));
    beginLabel.setText("Date de début");
    beginLabel.setForeground(new java.awt.Color(255, 255, 255));
    beginPanel.add(beginLabel, java.awt.BorderLayout.WEST);

    beginDatePicker.setFont(new java.awt.Font("Times New Roman", 1, 14));
    beginDatePicker.setPreferredSize(new java.awt.Dimension(120, 15));
    beginPanel.add(beginDatePicker, java.awt.BorderLayout.EAST);

    leftPanel.add(beginPanel);

    endPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    endPanel.setOpaque(false);
    endPanel.setPreferredSize(new java.awt.Dimension(160, 15));
    endPanel.setLayout(new java.awt.BorderLayout());

    endDatePanel.setOpaque(false);
    endDatePanel.setPreferredSize(new java.awt.Dimension(306, 10));
    endDatePanel.setLayout(new java.awt.BorderLayout());

    endDatePicker.setFont(new java.awt.Font("Times New Roman", 1, 14));
    endDatePicker.setPreferredSize(new java.awt.Dimension(120, 20));
    endDatePicker.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        DurationSpinner.setValue(
                (int)(endDatePicker.getDateInMillis() - beginDatePicker.getDateInMillis())/(1000*3600*24) + 1);
      }
    });
    endDatePanel.add(endDatePicker, java.awt.BorderLayout.EAST);

    endPanel.add(endDatePanel, java.awt.BorderLayout.EAST);

    endLabel.setFont(new java.awt.Font("Times New Roman", 1, 14));
    endLabel.setText("Date de fin");
    endLabel.setForeground(new java.awt.Color(255, 255, 255));
    endPanel.add(endLabel, java.awt.BorderLayout.WEST);

    leftPanel.add(endPanel);

    temp2 = new JPanel();
    temp2.setOpaque(false);
    temp2.setLayout(new BorderLayout());
    temp2.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
    temp2.add (new RoundedPanel(leftPanel), BorderLayout.CENTER);
    
    
    temp = new JPanel();
    temp.setOpaque(false);
    temp.setLayout(new BorderLayout());
    temp.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    temp.add (new RoundedPanel(rightPanel), BorderLayout.CENTER);
    

    
    temp3 = new JPanel();
    temp3.setOpaque(false);
    temp3.setLayout(new BorderLayout());
    temp3.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    temp3.add (new RoundedPanel(commentPanel), BorderLayout.CENTER);
        
    temp2.setBounds(10, 55, 270, 145);
    temp.setBounds(295, 55, 520, 145);
    temp3.setBounds(830, -30, 280, 165);
    
    jPanel1.setBounds(10, 10, 1066, 34);
    jPanel5.setBounds(22, 204, 1054, 34);
    
    temp2.setPreferredSize(new java.awt.Dimension(270, 145));
    temp.setPreferredSize(new java.awt.Dimension(520, 145));
    temp3.setPreferredSize(new java.awt.Dimension(280, 165));
    
    jPanel1.setPreferredSize(new java.awt.Dimension(520, 145));
    jPanel5.setPreferredSize(new java.awt.Dimension(270, 145)); 
    
    add(temp2);
    add(temp);
    add(temp3);
    add(jPanel1);
    add(jPanel5);
    
//    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
//    this.setLayout(layout);
//    layout.setHorizontalGroup(
//      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
//      .addGroup(layout.createSequentialGroup()
//        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
//          .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
//          .addGroup(layout.createSequentialGroup()
//            .addComponent(temp2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
//            .addGap(27, 27, 27)
//            .addComponent(temp, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE)
//            .addGap(26, 26, 26)
//            .addComponent(temp3, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE))
//          .addGroup(layout.createSequentialGroup()
//            .addContainerGap()
//            .addComponent(jPanel5, 0, 1036, Short.MAX_VALUE)))
//        .addContainerGap())
//    );
//    layout.setVerticalGroup(
//      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
//      .addGroup(layout.createSequentialGroup()
//        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
//        .addGap(11, 11, 11)
//        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
//          .addGroup(layout.createSequentialGroup()
//            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
//              .addComponent(temp, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
//              .addComponent(temp3, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
//            .addGap(9, 9, 9))
//          .addGroup(layout.createSequentialGroup()
//            .addComponent(temp2, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
//            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
//        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
//        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
//        .addContainerGap(16, Short.MAX_VALUE))
//    );
    
    setBackgroundPainter(new sheep.view.utils.swingx.PainterBlackCustom());
    //add(new RoundedPanel(MainPanel));    
    /*
    MainPanel = new JXPanel();
    centerPanel = new javax.swing.JPanel();
    
    
    mainPanel = new javax.swing.JPanel();

    
    northPanel = new javax.swing.JPanel();
    
    javax.swing.JLabel mainTitleLabel = new javax.swing.JLabel();
    
    cornerQuitBttn = new javax.swing.JButton();
    southPanel = new javax.swing.JPanel();
    validBttn = new ActionButton();
    quitBttn = new ActionButton();

    setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    setOpaque(false);
    setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));

    MainPanel.setBackground(new java.awt.Color(255, 255, 255));
    //MainPanel.setMaximumSize(new java.awt.Dimension(2147483647, 300));
    //MainPanel.setMinimumSize(new java.awt.Dimension(73, 300));
    //MainPanel.setPreferredSize(new java.awt.Dimension(100, 300));
    MainPanel.setLayout(new java.awt.BorderLayout());

    
    centerPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 10));
    centerPanel.setOpaque(false);
    centerPanel.setLayout(null);
    //centerPanel.setLayout(new java.awt.BorderLayout());

    mainPanel.setOpaque(false);
    centerPanel.add(mainPanel, java.awt.BorderLayout.CENTER);    
       
    
 
    
    
    

    MainPanel.add(centerPanel, java.awt.BorderLayout.CENTER);

    northPanel.setOpaque(false);
    northPanel.setLayout(new java.awt.BorderLayout());
    northPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 15, 10));
    mainTitleLabel.setFont(new java.awt.Font("Tahoma", 1, 20));
    mainTitleLabel.setForeground(new java.awt.Color(255, 255, 255));
    mainTitleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    mainTitleLabel.setText("Création tache");
    northPanel.add(mainTitleLabel, java.awt.BorderLayout.CENTER);

    cornerQuitBttn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/button-close.png"))); // NOI18N
    cornerQuitBttn.setToolTipText("Close editor");
    cornerQuitBttn.setBorder(null);
    cornerQuitBttn.setBorderPainted(false);
    cornerQuitBttn.setContentAreaFilled(false);
    cornerQuitBttn.setFocusPainted(false);
    cornerQuitBttn.setFocusable(false);
    cornerQuitBttn.setMargin(new java.awt.Insets(0, 0, 0, 0));
    cornerQuitBttn.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/button-close-pressed.png"))); // NOI18N
    cornerQuitBttn.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/button-close-over.png"))); // NOI18N
    cornerQuitBttn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cornerQuitBttnActionPerformed(evt);
      }
    });
    northPanel.add(cornerQuitBttn, java.awt.BorderLayout.EAST);

    MainPanel.add(northPanel, java.awt.BorderLayout.PAGE_START);

    //southPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 1, 0, 1));
    southPanel.setOpaque(false);
    southPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 15, 5));

    validBttn.setText("   Ok    ");
    southPanel.add(validBttn);
    validBttn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        OKBttnActionPerformed(evt);
      }
    });
    
    quitBttn.setText("Annuler");
    quitBttn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        quitBttnActionPerformed(evt);
      }
    });
    southPanel.add(quitBttn);

    MainPanel.add(southPanel, java.awt.BorderLayout.PAGE_END);
    MainPanel.setOpaque(true);
    MainPanel.setBackgroundPainter(new sheep.view.utils.swingx.PainterBlackCustom());
    add(new RoundedPanel(MainPanel));
     
     */
     
    
  }// </editor-fold>

  private void cornerQuitBttnActionPerformed(java.awt.event.ActionEvent evt) {
    final Container parent = this.getParent();
    Animator fadeOut = AnimationUtil.createFadeOutAnimation(this);
    fadeOut.addTarget(new TimingTarget() {
      @Override
      public void begin() {
      if (repaintComponent!=null){
         for(int i = 0; i < repaintComponent.length; i++){              
            if (repaintComponent[i] instanceof ProjectNewPanel){
                ((ProjectNewPanel)repaintComponent[i]).r.setVisible(false);  
            }          
            repaintComponent[i].repaint();
            
         }
      }        
      
      }
      @Override
      public void end() {
        setVisible2(false);
        parent.repaint();
      }
      @Override
      public void timingEvent(float f) {}
      @Override
      public void repeat() {}
    });
    fadeOut.start();
}

  private void quitBttnActionPerformed(java.awt.event.ActionEvent evt) {
        final Container parent = this.getParent();
    Animator fadeOut = AnimationUtil.createFadeOutAnimation(this);
    fadeOut.addTarget(new TimingTarget() {
      @Override
      public void begin() {
      if (repaintComponent!=null){
         for(int i = 0; i < repaintComponent.length; i++){              
            if (repaintComponent[i] instanceof ProjectNewPanel){
                ((ProjectNewPanel)repaintComponent[i]).r.setVisible(false);  
            }          
            repaintComponent[i].repaint();
            
         }
      }      
      }
      @Override
      public void end() {
        setVisible2(false);
        parent.repaint();
      }
      @Override
      public void timingEvent(float f) {}
      @Override
      public void repeat() {}
    });
    fadeOut.start();
  }
 
    private void OKBttnActionPerformed(java.awt.event.ActionEvent evt) {
        final Container parent = this.getParent();
    Animator fadeOut = AnimationUtil.createFadeOutAnimation(this);
    fadeOut.addTarget(new TimingTarget() {
      @Override
      public void begin() {
      ///////////////////
        // FIN
        i++;
        Calendar calTemp = Calendar.getInstance();
        calTemp.setTime(beginDatePicker.getDate());
        
     if (getMode() == TaskCreateMode.EDIT){     
       workSpace.getSelectedTask().setName(titleTextField.getText());
        workSpace.getSelectedTask().setActualBeginTime(calTemp, false);//.getActualBeginTime().setTime(beginDatePicker.getDate());
        calTemp.setTime(endDatePicker.getDate());
        workSpace.getSelectedTask().setActualEndTime(calTemp, false);//.getActualEndTime().setTime(endDatePicker.getDate());
        workSpace.getSelectedTask().setComment(commentTextArea.getText());
        workSpace.getSelectedTask().setDuration((Integer)DurationSpinner.getValue(), true);
      }else{
        Task t = workSpace.getSelectedTask();
        t.setName(titleTextField.getText());
        t.setDuration((Integer)DurationSpinner.getValue(), false);
        t.setActualBeginTime(calTemp, false);
        calTemp.setTime(endDatePicker.getDate());
        t.setActualEndTime(calTemp, false);
        t.setDuration((Integer)DurationSpinner.getValue(), true);
        t.setComment(commentTextArea.getText());
        t.setSuperTask(workSpace.getCurrentTask());
        
        workSpace.getCurrentTask().getGraph().addVertex(t);
        
        for (Task t2 :  usersTableModel2.getList())
          workSpace.getCurrentTask().getGraph().addEdge(t2, t);

      }
     
     
      if (repaintComponent!=null){
         for(int i = 0; i < repaintComponent.length; i++){              
            if (repaintComponent[i] instanceof ProjectNewPanel){
                ((ProjectNewPanel)repaintComponent[i]).refresh();
                ((ProjectNewPanel)repaintComponent[i]).r.setVisible(false);  
            }          
            repaintComponent[i].repaint();
            
         }
      }
      }
      @Override
      public void end() {
        setVisible2(false);
        parent.repaint();
      }
      @Override
      public void timingEvent(float f) {}
      @Override
      public void repeat() {}
    });
    fadeOut.start();
  }
    
    void setVisible2 (boolean aFlag){
    super.setVisible(aFlag);
    setEnabled(aFlag);
    setFocusable(aFlag);
    if (aFlag){
      ///////////////////////////
      //INIT
      ///////////////////////////
      if (getMode() == TaskCreateMode.EDIT ){
        titleLabel3.setText("Edition de la tache " + workSpace.getSelectedTask().getName());
        titleTextField.setText(workSpace.getSelectedTask().getName());
        DurationSpinner.setValue(workSpace.getSelectedTask().getDuration());
        beginDatePicker.setDate(workSpace.getSelectedTask().getActualBeginTime().getTime());
        endDatePicker.setDate(workSpace.getSelectedTask().getActualEndTime().getTime());
        commentTextArea.setText(workSpace.getSelectedTask().getComment());
      }else{
        titleLabel3.setText("Création d'unt d'une tache");
        Task t = new Task("nouvelle tache", 1, workSpace);
        t.addGraph(workSpace.getCurrentTask());
        workSpace.setSelectedTask(t);
        titleTextField.setText("Nouvelle tache " + i);
      }

      
      LinkedList<Task> list1 = new LinkedList<Task>();
      LinkedList<Task> list2 = new LinkedList<Task>();

       list2 = workSpace.getCurrentTask().getTaskList(false, false);
       if (getMode() == TaskCreateMode.EDIT ){
        if (workSpace.getCurrentTask()!= workSpace.getSelectedTask() && workSpace.getSelectedTask()!=null)
        for ( Object o : workSpace.getCurrentTask().getGraph().getVertex(workSpace.getSelectedTask()).getPredecessors()){
            list1.add(workSpace.getCurrentTask().getGraph().getTask((OurVertex)o));         
          }
        list2.removeAll(list1);
        list2.remove(workSpace.getCurrentTask());
        list2.remove(workSpace.getSelectedTask());
       }else{
         list2.remove(workSpace.getCurrentTask());
       }
      
      LinkedList<Task> list3 = workSpace.getCurrentTask().getTaskList(false, false);
      list3.removeAll(list2);
      list3.remove(workSpace.getCurrentTask());
      if (getMode() == TaskCreateMode.EDIT )
        list3.remove(workSpace.getSelectedTask());
      usersTableModel.setData(list2);
      tasksTable.setModel(usersTableModel);
      tasksTable.repaint();      
      
      usersTableModel2.setData(list3);
      predecesseurTable.setModel(usersTableModel2);
      predecesseurTable.repaint();
    }
  }


  
  @Override
  public void setVisible(final boolean aFlag) {
    final Container parent = this.getParent();
    
    if (!aFlag){ 
      Animator fadeOut = AnimationUtil.createFadeOutAnimation(this);
      fadeOut.addTarget(new TimingTarget() {
        @Override
        public void begin() {
        
        }
        @Override
        public void end() {
            setVisible2(false);
            parent.repaint();
            
        }
        @Override
        public void timingEvent(float f) {}
        @Override
        public void repeat() {}
      });
      fadeOut.start();
    }else{
        Animator fadeIn = AnimationUtil.createFadeInAnimation(this);
        fadeIn.addTarget(new TimingTarget() {
        @Override
        public void begin() {

          setVisible2(true);
        }
        @Override
        public void end() {
          parent.repaint();
        }
        @Override
        public void timingEvent(float f) {}
        @Override
        public void repeat() {}
      });
      fadeIn.start();   
    }
  }
  

  
  
  // Variables declaration - do not modify
  private javax.swing.JSpinner DurationSpinner;
  private javax.swing.JButton addButton;
  private org.jdesktop.swingx.JXDatePicker beginDatePicker;
  private javax.swing.JLabel beginLabel;
  private javax.swing.JPanel beginPanel;
  private javax.swing.JLabel calendrierLabel;
  private javax.swing.JPanel calendrierPanel;
  private javax.swing.JLabel commentLabel;
  private javax.swing.JPanel commentPanel;
  private javax.swing.JScrollPane commentScrollPane;
  private javax.swing.JTextArea commentTextArea;
  private javax.swing.JLabel endDateMinLabel1;
  private javax.swing.JPanel endDatePanel;
  private javax.swing.JPanel endDatePanel1;
  private org.jdesktop.swingx.JXDatePicker endDatePicker;
  private javax.swing.JLabel endLabel;
  private javax.swing.JPanel endPanel;
  private javax.swing.JButton jButton5;
  private javax.swing.JButton jButton6;
  private javax.swing.JButton jButton7;
  private javax.swing.JButton jButton8;
  private javax.swing.JButton jButton9;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JPanel jPanel3;
  private javax.swing.JPanel jPanel4;
  private javax.swing.JPanel jPanel5;
  private javax.swing.JScrollPane jScrollPane2;
  private javax.swing.JScrollPane jScrollPane3;
  private javax.swing.JPanel leftPanel;
  private JXTable predecesseurTable;
  private javax.swing.JButton remButton;
  private javax.swing.JPanel rightPanel;
  private JXTable tasksTable;
  private javax.swing.JLabel titleLabel;
  private javax.swing.JLabel titleLabel1;
  private javax.swing.JLabel titleLabel2;
  private javax.swing.JLabel titleLabel3;
  private javax.swing.JPanel titlePanel;
  private javax.swing.JTextField titleTextField;
  // End of variables declaration
  
  
  Calendrier c;
}



